package com.swsc.xapp.xroom;

import androidx.room.Room;

import com.swsc.xapp.utils.ContextUtils;

public abstract class BaseService {
    protected AppDatabase db = null;
    public BaseService(){
        if(null == db){
            db = Room.databaseBuilder(ContextUtils.getCurApplication(),
                    AppDatabase.class, "solar_verse").build();
        }
    }

    protected StringBuilder parseBaseParamsBuilder(Integer tenantNo, Integer organNo){
        StringBuilder sqlBuilder = new StringBuilder("");
        if(null != tenantNo){
            sqlBuilder.append(" AND tenant_no = ").append(tenantNo);
        }
        if(null != organNo){
            sqlBuilder.append(" AND organ_no = ").append(organNo);
        }
        return sqlBuilder;
    }

    protected String parseBaseParams(Integer tenantNo, Integer organNo){
        StringBuilder sqlBuilder = parseBaseParamsBuilder(tenantNo, organNo);
        return sqlBuilder.toString();
    }

    protected String parsePage(Integer pageNo, Integer pageSize){
        if(null != pageNo && null != pageSize){
            return " LIMIT " + pageSize + " OFFSET " + ((pageNo - 1) * pageSize);
        }
        return "";
    }

}
